﻿<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>登录</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <!--link-->
    <link type="text/css" rel="stylesheet" href="css/style.css" />
    <link type="text/css" rel="stylesheet" href="css/login.css" />
    <!--js-->
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <div class="container">
        <div class="main">
            <div class="logo">
                <img src="img/logo.png" />
            </div>
            <div class="form_bar">
                <p class="register"><a href="/register" style="text-decoration: none">注册</a></p>
                <form class="form_content">
                    <p style="font-size:30px;">欢迎登录</p>
                    <p style="font-size:20px;letter-spacing:5px;">床垫监测管理系统</p>
                    <p style="font-size:16px;margin-top:15px;">TJ-V1.1</p>
                    <ul>
                        <li style="padding-left:24px;"><img src="img/icon_one.png" /><input class="username" placeholder="账号/手机号" /></li>
                        <li style="padding-left:24px;"><img src="img/icon_two.png" /><input type="password" class="password" placeholder="请输入密码" /></li>
                        <li><button type="button" id="btn">登录</button></li>
                    </ul>
                    <p class="form_forget">忘记密码?</p>
                </form>
            </div>

            <p class="footer">床垫科技集团 版权所有@2021 渝ICP备12345678号</p>
        </div>
    </div>
</body>
</html>
<script>
    $(function () {
        $("#btn").click(function () {
            let username=$(".username").val();
            let password=$(".password").val();
            if(username==null||username==''){
                alert('用户名不能为空！');
                return false;
            }
            if(password==null||password==''){
                alert('密码不能为空！');
                return false;
            }
            let data = {
                username:username,
                password:password
            }
             $.ajax({
                 url:"sys/manage/login",
                 contentType : "application/json;charsetset=UTF-8",//必须
                 type:"POST",
                 data:JSON.stringify(data),
                 datatype: "json",
                success:function (data) {
                     let parse = JSON.parse(data);
                     if(parse.flag==="success"){
                         //存入token
                         sessionStorage.setItem("token",data.token);
                         window.location.href=parse.url;
                     }else {
                         alert("登录出错！");
                     }
                 },
                 error:function (e) {
                     console.log("错误");
                 }
             })
        })
    })
</script>